package com.demo.webapp.ui.config;

import java.io.IOException;

import org.apache.commons.digester3.xmlrules.FromXmlRulesModule;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.Resource;

public class ComponentRulesModule extends FromXmlRulesModule {

	private String[] baseNames = new String[0];
	@Override
	protected void loadRules() {
		FileSystemResourceLoader loader = new FileSystemResourceLoader();
		try {
			if (baseNames != null && baseNames.length > 0) {
				for (String baseName : getBaseNames()) {
					Resource resource = loader.getResource(baseName);
					if (resource != null && resource.exists()) {
						loadXMLRules(resource.getInputStream());
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public String[] getBaseNames() {
		return baseNames;
	}
	public void setBaseNames(String[] baseNames) {
		this.baseNames = baseNames;
	}
}
